/*
 *  Copyright (c) Iris Dev. team. All rights reserved.
 *  See http://www.communico.pro/license for details.
 *
 */
#ifndef _AS_MEMCACHED_CONNECTOR_HPP__
#define _AS_MEMCACHED_CONNECTOR_HPP__ 1

#include <ASLoadableObject.hpp>
#include <ASModule.hpp>

#include <STLVector.hpp>

#define C_DEFAULT_CONN_TIMEOUT   10000
#define C_DEFAULT_IO_TIMEOUT     1000
#define C_DEFAULT_ERROR_TIMEOUT  10000
#define C_DEFAULT_CONTINUUM_ELTS 100

namespace CAS_MOD
{

/**
  @class ASMemcachedConnector ASMemcachedConnector.hpp <ASMemcachedConnector.cpp>
  @brief Application server memcached connector
*/
class ASMemcachedConnector:
  public CAS::ASModule
{
public:
	/**
	  @brief A constructor
	*/
	ASMemcachedConnector();

	/**
	  @brief Initialize module
	  @param oConfiguration - module configuration
	  @param oModulesPool - pool of modules
	  @param oObjectPool - pool of objects
	  @param oLogger - logger object
	  @return 0 - if success, -1 - otherwise
	*/
	INT_32 InitModule(CTPP::CDT      & oConfiguration,
	                  CAS::ASPool    & oModulesPool,
	                  CAS::ASPool    & oObjectPool,
	                  CAS::ASLogger  & oLogger);

	/**
	  @brief Initialize server hook
	  @param oConfiguration - module configuration
	  @param oGlobalPool - pool of global objects
	  @param oServerPool - pool of per-server objects
	  @param oLogger - logger object
	  @return 0 - if success, -1 - otherwise
	*/
	INT_32 InitServer(CTPP::CDT      & oConfiguration,
	                  CAS::ASPool    & oGlobalPool,
	                  CAS::ASPool    & oServerPool,
	                  CAS::ASLogger  & oLogger);

	/**
	  @brief Get object type
	  @return human-readable type of module
	*/
	CCHAR_P GetModuleType() const;

	/**
	  @brief Get handler name
	*/
	CCHAR_P GetObjectName() const;

	/**
	  @brief A destructor
	*/
	~ASMemcachedConnector() throw();
private:
	/** List of objects */
	STLW::vector<ASObject *> vObjects;

	/**
	  @brief Create and register new SQL connection
	  @param oConfig - module configuration
	  @param oGlobalPool - pool of global objects
	  @param oServerPool - pool of per-server objects
	  @param oLogger - logger object
	  @return 0 - if success, -1 - otherwise
	*/
	INT_32 CreateAndRegisterObject(CTPP::CDT      & oConfig,
	                               CAS::ASPool    & oGlobalPool,
	                               CAS::ASPool    & oServerPool,
	                               CAS::ASLogger  & oLogger);
};

EXPORT_HANDLER(ASMemcachedConnector)

} // namespace CAS_MOD
#endif // _AS_MEMCACHED_CONNECTOR_HPP__
// End.
